package com.ktg.mes.wm.service.impl;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ktg.common.core.domain.Result;
import com.ktg.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.utils.SecurityUtils;
import com.ktg.mes.md.domain.MdItem;
import com.ktg.mes.md.domain.MdProductStatisticsBom;
import com.ktg.mes.md.service.IMdItemService;
import com.ktg.mes.md.service.IMdProductStatisticsBomService;
import com.ktg.mes.pro.domain.ProItemNeed;
import com.ktg.mes.pro.domain.ProWorkorder;
import com.ktg.mes.pro.service.IProItemNeedService;
import com.ktg.mes.wm.domain.WmItemRecptLine;
import com.ktg.mes.wm.domain.WmQuantityRecord;
import com.ktg.mes.wm.domain.WmStockWillSelectParam;
import com.ktg.mes.wm.mapper.WmQuantityRecordMapper;
import com.ktg.mes.wm.service.IWmQuantityRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.wm.mapper.WmStockWillOutMapper;
import com.ktg.mes.wm.domain.WmStockWillOut;
import com.ktg.mes.wm.service.IWmStockWillOutService;



/**
 * 产品出库记录Service业务层处理
 *
 * @author byteco
 * @date 2022-12-15
 */
@Service
public class WmQuantityRecordServiceImpl extends ServiceImpl<WmQuantityRecordMapper,WmQuantityRecord> implements IWmQuantityRecordService
{


    /**
     * 数量关联查询，allAuantity 为条件 数量总和
     * @param record
     * @return
     */
    public List<WmQuantityRecord> findSumCount(WmQuantityRecord record){
        return getBaseMapper().findSumCount(record);
    };


    /**
     * 查询符合条件的记录个数
     * @param record
     * @return
     */
    public BigDecimal findExistCount(WmQuantityRecord record){
        return getBaseMapper().findExistCount(record);
    };


    /**
     * 插入或者更新数量
     * @param record
     * @return
     */
    public WmQuantityRecord insertOrUpdate(WmQuantityRecord record){
        BigDecimal bigDecimal = findExistCount(record);
        if (bigDecimal != null && bigDecimal.doubleValue() > 0){
            getBaseMapper().updateRecordQuantity(record);
        }else {
            getBaseMapper().insertRecord(record);
        }
        return record;
    };


}
